# 利用map批量检测用户名是否符合规范 => username符合规范, username不符合规范
# • 只能包含数据、字母、下划线，不以数字开头，长度在6-18之间


import re

# def username(str):
#     if re.findall(r"^[A-Za-z_][A-Za-z\d\_]{5,17}", str):
#         return str

# def usnm_check(str):
#     for i in str:
#         if map(username, i):
#             print("username符合规范")
#             return i
#         else:
#             print("username不符合规范")
#             return None

# str1 = ['fghjkl345678_223', '1asdawd']
# result = usnm_check(str1)
# print(list(result))

# filter把合法的用户名显示出来
# print(list(filter(username, str1)))

# 匿名函数+reduce实现 1*2*3*...*n
# result = reduce(lambda x, y: x * y, range(1, 6))
# print(result)

# filter函数:找出[1-100]能被3整除的数
# result = list(filter(lambda x: x % 3 == 0, range(1, 101)))
# print(result)

# map函数:求list[1-10]各项的平方
# result = list(map(lambda x: x ** 2, range(1,11)))
# print(result)


# 正数在前负数在后,整数从小到大,负数从大到小
# list1=[7,-8,5,4,0,-2,-5]
# result = (sorted(list1, key=lambda x:x * -10 + 10 if x <= 0 else x))
# print(result)


# 排序规则：小写<大写<奇数<偶数
s = 'asdf234GDSdsf23'
def str_sort(s):
    for i in s:
        if s.isdigit():
            if int(s) % 2 == 0:
                return (True,True,s)
            else:
                return (True,False,s)
        else:
            if s.isupper():
                return (False,True,s)
            else:
                return (False,False,s)

print(sorted(s,key=str_sort))
